package com.axonactive.yolo.service.internal;

import org.apache.log4j.Logger;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.scheduling.quartz.QuartzJobBean;

import com.axonactive.yolo.exception.SubcribedFlightNotFoundException;

public class QuartzJob extends QuartzJobBean {
	private final static Logger LOGGER = Logger.getLogger(QuartzJob.class);
	private Detector detector;
	private static int counter = 0;

	public void setDetector(Detector detector) {
		this.detector = detector;
	}

	protected void executeInternal(JobExecutionContext context)
			throws JobExecutionException {

		if (Detector.ISFINISHED == true) {
			LOGGER.info("Re run the subscribe flight job: " + ++counter);
			try {
				detector.detect();
			} catch (SubcribedFlightNotFoundException e) {
				LOGGER.info("run the subscribe flight problems ",e);
			}
		}
	}

}